package com.pengshun.modules.api.user.controller;

import com.pengshun.modules.api.coal.para.CoalBinessPara;
import com.pengshun.modules.api.coal.service.dto.MerchantDto;
import com.pengshun.modules.api.coal.validator.First;
import com.pengshun.modules.api.coal.validator.Fourth;
import com.pengshun.modules.api.coal.validator.Third;
import com.pengshun.modules.api.user.service.UserAttentionService;
import com.pengshun.modules.api.user.service.dto.UserAttentionDto;
import com.pengshun.modules.common.BaseResult;
import com.pengshun.modules.common.PagePara;
import com.pengshun.modules.domain.User;
import com.pengshun.modules.security.Authorization;
import com.pengshun.modules.security.CurrUserInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;

@RestController
@RequiredArgsConstructor
@Api(tags = "关注管理")
@RequestMapping("/api/user/attention")
@ApiIgnore
public class UserAttentionController {

    private final UserAttentionService attentionService;

    @ApiOperation(value = "新增关注")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "merchantId", value = "商户id", dataType = "string", required = true, paramType = "query"),
            @ApiImplicitParam(name = "merchantCategoryId", value = "类别id", dataType = "string", required = true, paramType = "query"),
            @ApiImplicitParam(name = "jwtToken", value = "jwtToken", dataType = "string", required = true, paramType = "header")
    })
    @PostMapping(value = "/add", produces = "application/json; charset=utf-8")
    @Authorization
    public BaseResult newAttention(@ApiIgnore @CurrUserInfo User user, @ApiIgnore @Validated(value = {First.class}) UserAttentionDto para ) throws Exception {
        para.setUserId(user.getId());
        BaseResult res = attentionService.newAttention(para);
        return res;
    }

    @ApiOperation(value = "删除关注")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userAttentionId", value = "主键id", dataType = "string", required = true, paramType = "query"),
            @ApiImplicitParam(name = "jwtToken", value = "jwtToken", dataType = "string", required = true, paramType = "header")
    })
    @PostMapping(value = "/delete", produces = "application/json; charset=utf-8")
    @Authorization
    public BaseResult delete(@ApiIgnore @CurrUserInfo User user, @ApiIgnore @Validated(value = {Third.class}) UserAttentionDto para ) throws Exception {
        para.setUserId(user.getId());
        BaseResult res = attentionService.deleteAttention(para);
        return res;
    }

    @ApiOperation(value = "查询关注列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page", value = "当前页", dataType = "int", required = true, paramType = "query"),
            @ApiImplicitParam(name = "size", value = "条数", dataType = "int", required = true, paramType = "query"),
            @ApiImplicitParam(name = "merchantCategoryId", value = "商户类别id 1煤炭贸易公司 2运输公司 ", required = true, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "lngX", value = "经度", dataType = "double", paramType = "query"),
            @ApiImplicitParam(name = "latY", value = "纬度", dataType = "double", paramType = "query"),
            @ApiImplicitParam(name = "jwtToken", value = "jwtToken", dataType = "string", required = true, paramType = "header")
    })
    @GetMapping(value = "/list", produces = "application/json; charset=utf-8")
    @Authorization
    public BaseResult delete(@ApiIgnore @CurrUserInfo User user, @ApiIgnore @Validated(value = {First.class}) CoalBinessPara para) throws Exception {
        para.setUserId(user.getId());
        BaseResult res = attentionService.getAttentionList(para);
        return res;
    }

    @ApiOperation(value = "查询是否关注商户")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "merchantId", value = "商户id ", required = true, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "jwtToken", value = "jwtToken", dataType = "string", required = true, paramType = "header")
    })
    @GetMapping(value = "/is-attention", produces = "application/json; charset=utf-8")
    @Authorization
    public BaseResult select(@ApiIgnore @CurrUserInfo User user, @ApiIgnore @Validated(value = {First.class}) MerchantDto para) throws Exception {
        para.setUserId(user.getId());
        BaseResult res = attentionService.selectBymerchantId(para);
        return res;
    }



}
